//
//  HomePageViewController.m
//  TongChe
//
//  Created by cwMac on 16/1/20.
//  Copyright © 2016年 cwMac. All rights reserved.
//

#import "HomePageViewController.h"
#import "cehuaView.h"
#import "headerView.h"
//#import "DingDanViewController.h"
//#import "ZDOrderController.h"
//#import "ZDController.h"
//#import "ZDWalletController.h"
//#import "ZDAccountSecureController.h"
//#import "ZDMessageController.h"
//
#import "BMAD.h"
//#import "BMWebController.h"
@interface HomePageViewController ()
@property (strong, nonatomic) cehuaView *ceHuaView;
@property (weak, nonatomic) IBOutlet pageView *pageView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *menuHeightConstraint;
@property (weak,nonatomic)IBOutlet UIButton *btnOne;
- (IBAction)showMenu;

- (IBAction)searchCarAction:(UITapGestureRecognizer *)recognizer;
@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    if (kScreenHeight >= 736) {
        _menuHeightConstraint.constant = 110.f;
    } else if (kScreenHeight == 568) {
        _menuHeightConstraint.constant = 85.f;
    } else if (kScreenHeight == 480) {
        _menuHeightConstraint.constant = 82.f;
    } else {
        _menuHeightConstraint.constant = 100.f;
    }
    BMLog(@"%.2f, %.2f", kScreenWidth, kScreenHeight);
    
//    weakSelf(self);
    self.ceHuaView = [[cehuaView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"ZDmenu" withExtension:@"plist"];
    self.ceHuaView.menuItems = [NSArray arrayWithContentsOfURL:url];
//    [self.ceHuaView setMenuClicked:^(NSIndexPath *indexPath) {
////
////        if (!indexPath) {
////            ZDPersonInfoController *personVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"persnoVC"];
////            [weakSelf showViewController:personVC sender:nil];
////            return;
////        }
////        
//        BOOL row = indexPath.row;
//        UIStoryboard *storyBoaard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        UIViewController *destVC;
//        switch (indexPath.section) {
//            case 0:
//                if (row) {
//                    destVC = [storyBoaard instantiateViewControllerWithIdentifier:@"orderVC"];
//                }
//                break;
//            case 1:
//                if (row) {
//                    destVC = [storyBoaard instantiateViewControllerWithIdentifier:@"walletVC"];
//                } else {
//                    destVC = [storyBoaard instantiateViewControllerWithIdentifier:@"zdVC"];
//                }
//                break;
//            case 2:
//                if (row) {
//                    destVC = [storyBoaard instantiateViewControllerWithIdentifier:@"msgVC"];
//                } else {
//                    destVC = [ZDAccountSecureController new];
//                }
//                break;
//            case 3:
//                destVC = [storyBoaard instantiateViewControllerWithIdentifier:@"settingVC"];
//                break;
//        }
//        if (destVC) {
//            [weakSelf showViewController:destVC sender:nil];
//        }
//    }];
    
//    [self.pageView setItmeClick:^(BMAD *ad) {
//        BMWebController *webVC = [BMWebController new];
//        webVC.path = [NSURL URLWithString:ad.linkSrc];
//        [self showViewController:webVC sender:nil];
//    }];
    
    [self getData];
    [_btnOne addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
}
//-(void)click
//{
//    DingDanViewController *dingDan = [[DingDanViewController alloc]init];
//    [self presentViewController:dingDan animated:<#(BOOL)#> completion:<#^(void)completion#>]
//}
- (void)getData
{
    BMRequest *request = [BMRequest requestWithPath:@"findAdList.htm" contentKey:@"adverList"];
    request.params = @{@"position": @2};
    [BMAD postWithRequest:request finish:^(BMResponse *response, NSError *error) {
        if (response.status == kResultOK) {
            self.pageView.banners = response.result;
            [self.pageView start];
        } else {
            [self showHint:@"获取广告列表失败"];
        }
        [self getMenuAD];
    }];
}

- (void)getMenuAD
{
    BMRequest *request = [BMRequest requestWithPath:@"findAdList.htm" contentKey:@"adverList"];
    request.params = @{@"position": @0};
    [BMAD postWithRequest:request finish:^(BMResponse *response, NSError *error) {
        if (response.status == kResultOK) {
            self.ceHuaView.pgView.banners = response.result;
            [self.pageView start];
        }
    }];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.pageView start];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.pageView stop];
}

//- (void)showMenu
//{
//    if ([[BMAccountManager sharedInstance] isLogin]) {
//        [ show];
//    } else {
//        BMLoginController *loginVC = [self.storyboard instantiateViewControllerWithIdentifier:@"loginVC"];
//        [self presentViewController:loginVC animated:YES completion:nil];
//    }
//}

//- (IBAction)searchCarAction:(UITapGestureRecognizer *)recognizer {
//    ZDCreateOrderController *createVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"createOrderVC"];
//    createVC.defaultIndex = recognizer.view.tag;
//    [self presentViewController:createVC animated:YES completion:nil];
//}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
